<template>
  <main-wrap class="ptp1">
    <div class="weui-cells__title">选择批示</div>
    <div class="weui-cells weui-cells weui-cells_radio">
        <label class="weui-cell weui-check__label" for="11">
            <div class="weui-cell__bd">
                <p>下发</p>
            </div>
            <div class="weui-cell__hd">
                <input type="radio" checked class="weui-check" name="radio1" id="11" @click="agree">
                <i class="weui-icon-checked"></i>
            </div>
        </label>
        <label class="weui-cell weui-check__label" for="x12">
            <div class="weui-cell__bd">
                <p>上报</p>
            </div>
            <div class="weui-cell__hd">
                <input type="radio" class="weui-check" name="radio1" id="x12" @click="unagree">
                <i class="weui-icon-checked"></i>
            </div>
        </label>
    </div>

    <div class="weui-cells" v-show="false">
      <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">批示金额</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="number" pattern="[0-9]*" placeholder="请输入金额" v-model="money">
        </div>
      </div>
    </div>

    <!-- <div class="weui-cells__title" v-show="agree">意见</div>
    <my-textarea @areatextchg="areatextchg" v-show="agree"></my-textarea> -->
    <div class="weui-cells__title">意见</div>
    <my-textarea @areatextchg="areatextchg"></my-textarea>

    <my-uploader ref="uploader"></my-uploader>

    <div class="paddingP3 mtp4">
      <a href="javascript:;" class="weui-btn weui-btn_primary" :class="{'weui-btn_disabled': btnDisabled}" @click="gonext">处理</a>
    </div>
  </main-wrap>
</template>

<script>
import MyUploader from '@/components/myuploader'
import MainWrap from '@/components/mainWrap'
import MyTextarea from '@/components/mytextarea'
import { mapState, mapMutations } from 'vuex'

export default {
  name: 'Decision',
  data () {
    return {
      user_agree: true,
      money: 0,
      decisiontext: '',
      btnDisabled: true
    }
  },
  components: {
    MainWrap,
    MyTextarea,
    MyUploader
  },
  computed: {
    ...mapState(['user_report_upload_items', 'order_detail', 'user_report_upload_items_new'])
  },
  activated () {
    this.$refs.uploader.cleardata()
    this.empty_user_report_upload_items_new()

    this.checkinput()
  },
  watch: {
    decisiontext () {
      this.checkinput()
    },
    money () {
      this.checkinput()
    }
  },
  mounted () {
    this.dataInit()
  },
  methods: {
    ...mapMutations(['empty_user_report_upload_items_new', 'add_user_report_upload_items_new']),
    agree () {
      this.user_agree = true
      this.checkinput()
    },
    unagree () {
      this.user_agree = false
      this.checkinput()
    },
    gonext () {
      if (!this.btnDisabled) {
        const agree = this.user_agree
        // if(!agree){
        //   this.$toast.loading({
        //     duration: 200,
        //     message: '请选择处理方式'
        //   })
        //   return
        // }
        console.log(this.user_report_upload_items_new)
        this.$toast.loading({
          duration: 0,
          message: '请稍等...'
        })

        this.cm.myajax('/sys/userrepair/decision', {
          attachment: JSON.stringify(this.user_report_upload_items_new),
          repairId: localStorage.oid,
          agree: (agree ? '1' : '0'),
          cost: this.money,
          idea: this.decisiontext
        }, (data) => {
          this.$toast.clear()

          localStorage.ostat = '31'
          this.$router.push('/morderdetail/' + localStorage.oid)
          // this.$router.push({
          //   path: '/opersucc',
          //   query: {
          //     mainbtnurl: '/morderdetail',
          //     subbtnurl: '/mindex'
          //   }
          // })
        })
      }
    },
    areatextchg (text) {
      this.decisiontext = text
    },
    checkinput () {
      // if (!this.agree) {
      //   this.btnDisabled = false
      // } else {
      // if (this.decisiontext !== '' && this.money !== '') {
      if (this.decisiontext !== '') {
        this.btnDisabled = false
      } else {
        this.btnDisabled = true
      }
      // }
    },
    dataInit () {
      this.mrotype = this.order_detail.repairItemStr
      // this.code = this.order_detail.deviceNum
      // this.$refs.descriarea.setdata(this.order_detail.repairDesc)
      // this.money = this.order_detail.expectedCost

      this.empty_user_report_upload_items_new()
      this.$refs.uploader.cleardata()
    }
  }
}
</script>

<style lang="stylus" scoped>
.agreeWrap
  font-size: 17px
</style>
